package ferp.center.server.entity;

import com.google.appengine.api.datastore.Key;

import javax.persistence.*;

/**
 * User: igorgok
 * Date: 5/8/12 1:45 PM
 *
 * Ratings are kept per configuration
 */
@NamedQueries({
    @NamedQuery(name = RangeTree.QUERY_GET_BY_CONFIG,
                query = "SELECT r FROM RangeTree r WHERE r.configuration = ?1"),
    @NamedQuery(name = RangeTree.QUERY_GET_ALL,
                query = "SELECT r FROM RangeTree r")
})

@Entity
public class RangeTree
{
  public static final int UPDATE = 1;

  // get range tree for specific configuration
  public static final String QUERY_GET_BY_CONFIG = "getRangeTreeByConfig";
  // get all trees
  public static final String QUERY_GET_ALL = "getAllRangeTrees";

  public RangeTree(String configuration)
  {
    this.configuration = configuration;
  }

  public Key getRoot() {return root;}
  public Range getRoot(EntityManager em) {return em.find(Range.class, root);}
  public void setRoot(Range root) {this.root = root.getKey();}
  public void setRoot(Key key) {this.root = key;}
  public String getConfiguration() {return configuration;}
  public void setConfiguration(String configuration) {this.configuration = configuration;}

  public int getUpdate() {return update;}
  public void setUpdate() {this.update = UPDATE;}
  public void setUpdate(int update) {this.update = update;}

  // dummy
  protected RangeTree() {}

  @Id
  // game configuration
  private String configuration;
  // root range key
  private Key root;

  // update
  private Integer update = UPDATE;
}
